home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <sys/time.h>
-
- #include "fft.h"
- #include "constant.h"
-
- /* */
- /* Precision dependant declarations */
- /* */
- #ifdef DOUBLE
-
- #define TOLERANCE DTOLERANCE
- typedef double this_half;
- typedef double this_type;
-
- #define THIS_SUM dsum_
- #define THIS_GEN dgen_
- #define THIS_FT dft2d_
-
- #define THIS_FFTI dfft2di
- #define THIS_FFT dfft2d
- #define THIS_SCAL dscal2d
-
- #endif
- #ifdef SINGLE
-
- typedef float this_half;
- typedef float this_type;
-
- #define TOLERANCE STOLERANCE
-
- #define THIS_SUM ssum_
- #define THIS_GEN sgen_
- #define THIS_FT sft2d_
-
- #define THIS_FFTI sfft2di
- #define THIS_FFT sfft2d
- #define THIS_SCAL sscal2d
-
- #endif
-
- /* */
-
- this_half THIS_SUM();
-
- void inimat_();
- void GetArguments();
- void get_values();
-
- int size_x, ldx, size_y, n_trials;
- this_type *pa, *pb, *pRef, *pSave;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i, j, k, n_total, is_wrong, nerr, inc;
- double x, y, dx, dy, emax, sum, err, maxerr;
- this_half t;
- this_type *ptr;
-
- /* ******************************************************* */
- GetArguments( argc, argv);
- /* ******************************************************* */
-
- srandom( (123*getpid()) | 0x01);
-
- for( ; n_trials > 0; n_trials --) {
- get_values();
-
- printf("\n");
- printf( "%3d <%3d,%3d>", n_trials, size_x, size_y);
- fflush(stdout);
-
- n_total = ((size_x+2)*(size_y+1));
- ldx = size_x + 2;
- pa = (this_type *)malloc
- ( (3 * n_total + size_x + 3 * size_y + 4 * FACTOR_SPACE) * sizeof(this_type));
- if( !(pa) ) {
- fprintf( stderr, "Could not allocate ... Exiting\n");
- exit (-1);
- }
- pb = pa + n_total;
- pRef = pb + n_total;
- pSave = pRef + n_total;
-
- /* *******************************************************
- Initialize arrays
- ******************************************************* */
- THIS_GEN(pRef, &n_total);
- bcopy( pRef, pa, n_total*sizeof(this_type));
- bcopy( pRef, pb, n_total*sizeof(this_type));
-
- /* *******************************************************
- PACKED --- direct Fourier Transform
- ******************************************************* */
- j = -1;
- THIS_FT( &j, &size_x, &size_y, pb, &ldx);
- pSave = THIS_FFTI( size_x, size_y, pSave);
- bcopy( pRef, pa, n_total*sizeof(this_type));
- is_wrong = THIS_FFT( -1, size_x, size_y, pa, ldx, pSave);
-
- emax = TOLERANCE*(size_x * size_y);
- for(i = 0, nerr=0 ; i < n_total ; i ++) {
- x = pa[i] - pb[i];
- if( (t= x*x) > (emax)) {
- nerr++;
- }
- }
- if( !(nerr)){
- fprintf( stderr, ".");
- }
- else {
- fprintf( stderr, "@%d@", nerr);
- }
- inc = 1;
- x = y = 0;
- for( j= 0, ptr = pRef ; j < size_y ; j++, ptr += ldx) {
- x += THIS_SUM( &size_x, ptr, &inc);
- }
- dx = x - pa[0];
- if( (t= dx *dx) > TOLERANCE){
- fprintf( stderr,
- "\nError direct FFT(%d,%d) at index #0 : (%f)<->(%f)error(%f)",
- size_x, size_y, pa[0], x, dx);
- }
- dx = x - pb[0];
- if( (t= dx *dx) > TOLERANCE){
- fprintf( stderr,
- "\nError direct DFT(%d,%d) at index #0 : (%f)<->(%f)error(%f)",
- size_x, size_y, pb[0],x,dx);
- }
- /* *******************************************************
- PACKED --- inverse Fourier Transform
- ******************************************************* */
- is_wrong = THIS_FFT( 1, size_x, size_y, pa, ldx, pSave);
-
- x = 0;
- j = (size_y -1) / 2;
- inc = 2 * ldx;
-
- t = 1. / (double)(size_x * size_y);
- THIS_SCAL( size_x, size_y, t, pa, ldx);
-
- emax = TOLERANCE;
- emax = emax * emax;
-
- sum = 0.;
- err= 0.;
- nerr= 0;
- maxerr= 0.;
- for(i = 0 ; i < n_total ; i ++) {
- sum += (pRef[i] * pRef[i]) + (pRef[i] * pRef[i]);
- x = pa[i] - pRef[i];
- if( (t= x*x) > (emax))
- nerr++;
- err += t;
- if( t > maxerr) maxerr = t;
- }
- err = sqrt(err / (double)(size_x*size_y));
- sum = sqrt(sum / (double)(size_x*size_y));
- maxerr = sqrt(maxerr);
- printf(": avg:(%8.3g /%8.3g)= %8.3g <> maxerr: (%8.3g /%8.3g)= %8.3g",
- err, sum, err/sum, maxerr, sum, maxerr/sum);
- if(nerr){
- printf("\n%d errors detected \n", nerr);
- exit(-2);
- }
- free(pa);
- }
- printf("\n");
- return(0);
- }
-
- int is_random;
-
- void GetArguments( argc, argv)
- int argc;
- char *argv[];
- {
- int i, j, k;
- int nerror = 0;
-
- #define ON 1
-
- n_trials = DEF_TRIALS;
- is_random = 1;
-
- /* ******************************************************* */
- for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
- if( argv[i][0] == '-') {
- switch ( argv[i][1]) {
- case 'i' :
- case 'I' :
- is_random = 0;
- break;
- default : nerror = ON;
- }
- }
- else {
- if( i+1 > argc)
- nerror = ON;
- else {
- n_trials = atoi( argv[i]);
- }
- }
- }
- if( nerror == ON) {
- fprintf( stderr,
- "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
- exit(-1);
- }
- }
-
- void get_values()
- {
- if( is_random){
- size_x = random() % MAX_2D + 1;
- size_y = random() % MAX_2D + 1;
- if( !(n_trials % 5))
- size_y = size_x;
- } else{
- printf( "Enter SIZE_X : ");
- scanf("%d", &size_x);
- printf( "Enter SIZE_Y : ");
- scanf("%d", &size_y);
- }
- }
-